package cn.bulibuqi.myblog.service;

import cn.bulibuqi.myblog.bean.Tag;

import cn.bulibuqi.myblog.dao.TagMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;


/**
 * @author bulibuqi
 * @create 2021-12-21:56
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper,Tag> implements  TagService{

    @Override
    public boolean saveTag(Tag tag) {

        boolean save = save(tag);
        return save;
    }

    @Override
    public Tag getTag(Long id) {

        Tag byId = getById(id);
        return byId;
    }

    @Override
    public Page<Tag> listTag(Page pageInfo) {

        Page<Tag> page = page(pageInfo);

        return page;
    }


    @Override
    public boolean updateTag(Long id, Tag tag) {
        tag.setId(id);
        boolean b = updateById(tag);


        return b;
    }

    @Override
    public void deleteTag(Long id) {
        removeById(id);

    }

    @Override
    public Tag getTagByName(String name) {
        QueryWrapper<Tag> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        Tag one = getOne(queryWrapper);
        return one;
    }
}
